package com.qgzj.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import com.qgzj.util.AesUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * 用户信息表
 * </p>
 *
 * @author bianyangyang
 * @since 2018-04-19
 */
@Data
@Accessors(chain = true)
public class SysUser extends Model<SysUser> {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 用户编号
     */
    private String userNo;
    /**
     * 登录账号
     */
    private String accountNo;
    /**
     * 姓名
     */
    private String userName;
    /**
     * 性别 1-男 2-女
     */
    private Integer sex;
    @TableField(exist = false)
    private String sexStr;
    /**
     * 头像
     */
    private String headImage;

    /**
     * 微信openid
     */
    private String openid;
    /**
     * 昵称
     */
    private String nickName;
    /**
     * 手机号码
     */
    private String mobile;
    /**
     * 密码
     */
    private String password;

    private String salty;
    /**
     * 真实姓名
     */
    private String realName;
    /**
     * 身份证号码
     */
    private String identityNo;
    /**
     * 证件类型
     */
    private Integer certificateType;
    @TableField(exist = false)
    private String certificateTypeStr;
    /**
     * 联系电话
     */
    private String contactTel;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 工会编号
     */
    private String unionNo;
    /**
     * 工会名称
     */
    @TableField(exist = false)
    private String unionName;
    /**
     * 会员编号
     */
    private String memberNo;
    /**
     * 积分
     */
    private Integer integralValue;
    /**
     * 成长值
     */
    private Integer grownValue;
    /**
     * 用户类型 1-后台用户 2-pc h5用户
     */
    private Integer userType;
    /**
     * 注册来源(积分这期需要把这移动到member_info表。暂时未动) 1-管理后台 2-会员后台 3-新闻cms 4-H5 5-PC
     */
    private Integer source;
    /**
     * 1-有效 0-无效
     */
    private Integer status;
    /**
     * 职务
     */
    private String duty;
    /**
     * 备注信息
     */
    private String memo;
    /**
     * 职工卡所属银行
     */
    private String bankCode;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 修改时间
     */
    private Date updateTime;

    /**
     * 申请人类型:1=职工 2=企业
     */
    private Integer proposerType;
    @TableField(exist = false)
    private String proposerTypeStr;

    @ApiModelProperty(value = "是否是管理者1是0否", name = "isManager")
    private Integer isManager;

    @TableField(exist = false)
    private Integer unionProp;
    /**
     * 籍贯
     */
    private String nativePlace;

    @ApiModelProperty(value = "职工服务卡号", name = "staffCardNo", required = true)
    private String staffCardNo;

    @ApiModelProperty(value = "工作单位", name = "workUnit", required = true)
    private String workUnit;

    @ApiModelProperty(value = "部门编号", name = "deptNo", required = true)
    private String deptNo;
    @TableField(exist = false)
    private String deptName;

    @TableField(exist = false)
    @ApiModelProperty(value = "是否是领导", name = "isLeader")
    private Integer isLeader;
    @TableField(exist = false)
    private String leaderNo;

    @TableField(exist = false)
    @ApiModelProperty(value = "是否有邀请权限", name = "authInvite")
    private Integer authInvite;

    @TableField(exist = false)
    @ApiModelProperty(value = "上级工会名称", name = "parentUnionName")
    private String parentUnionName;

    @ApiModelProperty(value = "会员等级", name = "gradeInfoDesc")
    @TableField(exist = false)
    private String gradeInfoDesc;

    @ApiModelProperty(value = "是否报警", name = "1=是 2=否")
    private Integer jfAlarmType;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    public String getRealName(){
        if (StringUtils.isNotEmpty(realName) && realName.endsWith("==")){
            realName = AesUtil.decrypt(realName);
        }
        return realName;
    }

}
